﻿using L.Tool;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LoadScene : MSingleton<LoadScene>
{
    private MaskPanel maskPanel;
    private void Start()
    {
        maskPanel = UIManager.Instance.allUIs[UIPanelType.MaskPanel].GetComponent<MaskPanel>();
    }
    /// <summary>
    /// 加载场景
    /// </summary>
    /// <param name="name"></param>
    public void LoadTheScene(string name)
    {
        //异步加载场景
        StartCoroutine(LoadSceneAsync(name));
    }

    /// <summary>
    /// 异步加载场景
    /// </summary>
    /// <param name="name"></param>
    /// <returns></returns>
    private IEnumerator LoadSceneAsync(string name)
    {
        GameObject.Find(" Directional Light")?.SetActive(false);
        maskPanel.OnActiveTrue();
        yield return new WaitForSeconds(1f);
        AsyncOperation asyncLoad = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(name);
        while (!asyncLoad.isDone)
        {
            maskPanel.Process = asyncLoad.progress;
            yield return null;
        }
        maskPanel.OnActiveFalse();
        maskPanel.Process = 0;

    }
}
